/**
 * 
 */
package name.nano.client.view;

import name.nano.client.FrisbeeTacticBoard;
import name.nano.client.GameBoard;
import name.nano.client.utils.Coordinate;

import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseDownHandler;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.Widget;

final class MouseListenerImplementation implements MouseDownHandler,MouseUpHandler,MouseMoveHandler, MouseListener  {
	private GameBoard m_board;
	private FrisbeeTacticBoard m_simulator;
	public MouseListenerImplementation(FrisbeeTacticBoard simulator) {
		this.m_board=simulator.m_gameBoard;
		m_simulator=simulator;
	}
	
	@Override
	public void onMouseDown(Widget sender, int x, int y) {
		Coordinate p1=new Coordinate(x,y);
		onMouseDown(p1);
	}

	@Override
	public void onMouseEnter(Widget sender) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onMouseLeave(Widget sender) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onMouseMove(Widget sender, int x, int y) {
		Coordinate p1=new Coordinate(x,y);
		onMouseMove(p1);

		
	}

	@Override
	public void onMouseUp(Widget sender, int x, int y) {
		Coordinate p1=new Coordinate(x,y);
		onMouseUp(p1);
	}

	@Override
	public void onMouseMove(MouseMoveEvent event) {
		Coordinate p1=new Coordinate(event.getX(),event.getY());
		onMouseMove(p1);

	}


	@Override
	public void onMouseDown(MouseDownEvent event) {
		Coordinate p1=new Coordinate(event.getX(),event.getY());
		onMouseDown(p1);
	}


	@Override
	public void onMouseUp(MouseUpEvent event) {
		Coordinate p1=new Coordinate(event.getX(),event.getY());
		onMouseUp(p1);
	}

	private void onMouseMove(Coordinate p1) {
		Coordinate downEv = m_simulator.toLogicalCoordinates(p1);
		
		m_board.onMouseMove(downEv);
		
		m_simulator.redraw();
	}
	private void onMouseDown(Coordinate p1) {
		Coordinate downEv = m_simulator.toLogicalCoordinates(p1);
		
		m_board.onMouseDown(downEv);
		
		m_simulator.redraw();
	}
	private void onMouseUp(Coordinate p1) {
		Coordinate downEv = m_simulator.toLogicalCoordinates(p1);
		m_board.onMouseUp(downEv);
		m_simulator.redraw();
	}


}